import 'package:flutter/material.dart';
import 'package:flutter_shop/model/cartInfo.dart';
import 'package:flutter_shop/pages/cart_page/cart_bootom.dart';
import 'package:flutter_shop/pages/cart_page/cart_item.dart';
import 'package:flutter_shop/pages/details_page/details_bottom.dart';
import 'package:flutter_shop/provide/cart.dart';
import 'package:flutter_shop/provide/counter.dart';
import 'package:provide/provide.dart';

class CartPage extends StatefulWidget {
  @override
  _cartPageState createState() => _cartPageState();
}

class _cartPageState extends State<CartPage> {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text('购物车'),
      ),
      body: FutureBuilder(
        future: _getCarInfo(context),
        builder: (context, snapshot) {
          return Provide<CartProvide>(
            builder: (context, child, cartIndoDate) {
              return Stack(
                children: <Widget>[
                  Container(
                    child: ListView.builder(
                      itemBuilder: (context, index) {
                        return CartItem(cartInfoMode: cartIndoDate.cartList[index],);
                      },
                      itemCount: cartIndoDate.cartList.length,
                    ),
                  ),
                  Positioned(child: CartBootom(),left:0 ,bottom: 0,),
                ],
              );
            },
          );
        },
      ),
    );
  }

//  List cartList=Provide.value<CartProvide>(context).cartList;
//  if(snapshot.hasData && cartList!=null){
//  return Stack(
//  children: <Widget>[
//  Provide<CartProvide>(
//
//  builder: (context,child,childCategory){
//  cartList= Provide.value<CartProvide>(context).cartList;
//  print(cartList);
//  return ListView.builder(
//  itemCount: cartList.length,
//  itemBuilder: (context,index){
//  return ListTile(
//  title: Text(cartList[index].goodsName),
//  );
//  },
//  );
//  }
//  ),
//  ],
//  );
//  }else{
//  return Text('正在加载');
//  }

  Future<String> _getCarInfo(BuildContext context) async {
    await Provide.value<CartProvide>(context).getCartInfo();
    return 'end';
  }
}
